package com.medica.ledproject.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.medica.ledproject.common.BxyUtil;
import com.medica.ledproject.common.CustomException;
import com.medica.ledproject.entity.DzParkLedscree;
import com.medica.ledproject.entity.DzParkLedscreeRespon;
import com.medica.ledproject.entity.DzParkZha;
import com.medica.ledproject.entity.RequestPro;
import com.medica.ledproject.mapper.DzParkLedscreeMapper;
import com.medica.ledproject.mapper.DzParkZhaMapper;
import com.medica.ledproject.service.IDzParkLedscreeService;
import com.medica.ledproject.service.IDzParkZhaService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * LED屏幕 服务实现类
 * </p>
 *
 * @author xiaona
 * @since 2024-05-29
 */
@Slf4j
@Service
public class DzParkZhaServiceImpl extends ServiceImpl<DzParkZhaMapper, DzParkZha> implements IDzParkZhaService {
    @Resource
    DzParkZhaMapper dzParkZhaMapper;
    @Override
    public boolean updateZha(String data, String ip) {
        if(!StringUtils.isEmpty(ip)){
            DzParkZha d=dzParkZhaMapper.selectOne(new QueryWrapper<DzParkZha>().eq("ip",ip));
            if(d!=null){
                if("01 05 00 02 FF 00 2D FA".equals(data)){
                    //断电（关）
                    d.setStatus(2);
                }else{
                    //通电（开）
                    d.setStatus(1);
                }
                d.setLasttime(LocalDateTime.now());
                return dzParkZhaMapper.updateById(d)>0;
            }else{
                log.info("没有查询到ip为{}的设备",ip);
            }
        }
        return false;
    }
}
